<!DOCTYPE html>
<html>
{{template "inc_bodyHead" "搜索"}}
<body>

{{template "inc_header" .}}

<div id="main">
    <div id="main-inner">
        <div id="search-cloud" class="clouds">
            <h3 class="clouds-title">搜索</h3>
            <div class="search">
                <form action="/search" method="get" id="search-form" >

                    <span>{{if .TagName}}标签：<a class="tag" href="/search/tag/{{.TagName}}">{{.TagName}}</a><sup id="delSearchTag">X</sup>{{end}}</span>

                    分类：
                    <select id="postType1" title="" >
                        <option value="0">全部</option>
                    </select>

                    <select id="postType2" title="" >
                        <option value="0">全部</option>
                    </select>

                    关键字：<input type="text" name="keyWord" placeholder="请输入关键字" value="{{.KeyWord}}" />
                    <input type="hidden" name="type" value="{{.TypeId}}" />
                    <input type="hidden" name="tagName" value="{{.TagName}}" />
                    <input type="submit" value="搜索" />
                </form>
            </div>

            <div id="search-result">
                {{range .ResultList.Lists}}
                <div class="post-search-list">
                    <div class="post-title-meta">
                        <span class="left">
                            ➤
                            <b>
                                <a href="/read/{{.Id}}">{{.TitleHtml}}</a>
                            </b>
                            <i>{{.PostTypeHtml}}</i>
                        </span>

                        <span class="meta right">{{.FmtShowTime}}</span>
                    </div>
                </div>
                {{else}}
                <span>搜索结果为空...</span>
                {{end}}
            </div>

            <!-- 分页 -->
            {{Pager .Page .ResultList.PageNum .BaseUrl}}

        </div>
    </div>
</div>

{{template "inc_footer" .}}

<script type="application/javascript" src="/js/jquery.pagination.js"></script>
<script type="text/javascript">
    curentPage = {{.Page}};
    pageCount={{.ResultList.PageNum}};
    keyWord = {{.KeyWord}};
    TagName = {{.TagName}};
    typeId = {{.TypeId}};



    typesInfoJson = eval('('+ {{.TypesInfoJson}} + ')');
    TypeListJson = eval('('+ {{.TypeListJson}} + ')');
    type1Opt = type2Opt = "<option value='0'>全部</option>";
    type1Child = null;
    $(TypeListJson).each(function (i,obj) {
        if(typesInfoJson.fid==0){
            if(typesInfoJson.id==obj.id){
                type1Opt += "<option value='"+obj.id+"' selected >"+obj.id+"-"+obj.name+"</option>";
                type1Child = obj.child;
            }else{
                type1Opt += "<option value='"+obj.id+"' >"+obj.id+"-"+obj.name+"</option>";
            }
        }else{
            if(typesInfoJson.fid==obj.id){
                type1Opt += "<option value='"+obj.id+"' selected >"+obj.id+"-"+obj.name+"</option>";
                type1Child = obj.child;
            }else{type1Opt += "<option value='"+obj.id+"' >"+obj.id+"-"+obj.name+"</option>";
            }
        }
    });
    $('#postType1').html(type1Opt);
    if(type1Child){
        $(type1Child).each(function (i,obj) {
            if(typesInfoJson.fid!=0 && typesInfoJson.id==obj.id){
                type2Opt+= "<option value='"+obj.id+"' selected >"+obj.id+"-"+obj.name+"</option>";
            }else{
                type2Opt+= "<option value='"+obj.id+"' >"+obj.id+"-"+obj.name+"</option>";
            }
        });
    }
    $('#postType2').html(type2Opt);
    $('#postType1').on("change",function () {
        type2Opt = "<option value='0'>全部</option>";
        sonId = $(this).find("option:selected").val();
        $('#search-cloud input[name=type]').val(sonId);
        if(sonId=="0"){
            $('#postType2').html("<option value='0'>全部</option>");
        }else{
            $(TypeListJson).each(function (i,obj) {
                if(sonId==obj.id){
                    $(obj.child).each(function (i,obj2) {
                        type2Opt+= "<option value='"+obj2.id+"' >"+obj2.id+"-"+obj2.name+"</option>";
                    });
                }
            })
        }
        $('#postType2').html(type2Opt);
    });
    $('#postType2').on("change",function () {
        sonId = $(this).find("option:selected").val();
        if(sonId==0){
            sonId = $('#postType1 option:selected').val();
        }
        $('#search-cloud input[name=type]').val(sonId);
    });
    $('#delSearchTag').on('click',function () {
        $('#search-cloud input[name=tagName]').val("");
        $('#search-form').submit();
    });

</script>
</body>
</html>